package gcu.module.owner.dao;

import gcu.module.owner.dao.mapper.OwnerMapper;
import gcu.module.owner.daomain.Owner;
import gcu.util.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by haol on 2016/9/23.
 */
@Repository
public class OwnerDao {

      private Logger logger = LoggerFactory.getLogger(OwnerDao.class);
      @Autowired
      private OwnerMapper mapper;


      /*获取全部角色*/
      public List<Owner> queryOwnerList(Owner owner, Pager pager) {
            try {
                  int skip = (pager.getCurrentPage() - 1) * pager.getPageSize();
                  int pageSize = pager.getPageSize();
                  pager.setTotalSize(mapper.count(owner));
                  return mapper.query(owner,skip,pageSize);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }

      }
      /*z增加用户*/
      public void addOwner(Owner owner) {
            try {
                  mapper.addOwner(owner);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }


      /*删除用户*/
      public void deleteOwner(Integer id) {
            try {
                  mapper.deleteOwner(id);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }
      public void deleteOwner(List list) {
            try {
                  mapper.deleteOwnerByList(list);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }

      /*更新用户*/
      public void updateOwner(Owner owner) {
            try {
                  mapper.updateOwner(owner);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }

      public void setMoneyInfo(int ownerId,int isMoney) {
            try {
                  mapper.setMoneyInfo(ownerId,isMoney);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }

      public Owner queryOwnerById(Integer id) {
            try {
                  return mapper.queryOwnerById(id);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }
      public Owner queryOwnerByBuildAndRoom(String buildName,String roomNum) {
            try {
                  return mapper.queryOwnerByBuildAndRoom(buildName,roomNum);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }
      public Owner  queryOwnerByName(String ownerName){
            try {
                  return mapper.queryOwnerByName(ownerName);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }
      public Owner  queryOwnerByCreateTime(String createTime){
            try {
                  return mapper.queryOwnerByCreateTime(createTime);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }
      public List<Owner>  queryOwnerByBuild(String buildName){
            try {
                  return mapper.queryOwnerByBuild(buildName);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }
}
